package com.xqls.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xqls.biz.CompanyBiz;
import com.xqls.biz.DischargeRealdataBiz;
import com.xqls.biz.RainwaterDischargeRealdataBiz;
import com.xqls.biz.RemotecontrolBiz;
import com.xqls.util.CommonResult;
import com.xqls.util.DictionaryEnums;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value="/valve")
public class ValveChangeController {
	@Autowired private DischargeRealdataBiz dischargeBiz;
	@Autowired
	private CompanyBiz companyBiz;
	@Autowired private RainwaterDischargeRealdataBiz rainwaterBiz;
	@Autowired private RemotecontrolBiz  remoteBiz;
	@RequestMapping(value="/dischargeValveChange")
	public  ModelAndView dischargeCalibration(){
		ModelAndView view=new ModelAndView("valveChange/dischargeChange");
		List<Map<String,Object>> dischargeList=dischargeBiz.queryAll();
		for (int i=0;i<dischargeList.size();i++){
			dischargeList.get(i).put("viewId",i+1);
		}
		view.addObject("isValveChange", true);
		view.addObject("dischargeList", dischargeList);
		view.addObject("title", "排放口阀门控制");
		return view;
		
	}
	
	@RequestMapping(value = "/radioDischargeValveChange/{device_no}")
	public ModelAndView radioDischargeCalibration(@PathVariable(value = "device_no") String device_no) {
		ModelAndView view = new ModelAndView("valveChange/dischargeChange");

		view.addObject("companyList", companyBiz.getList(DictionaryEnums.DISCHARGE));

		view.addObject("discharge",dischargeBiz.queryByDeviceNo(device_no));
		view.addObject("title", "排放口阀门控制");
		return view;
	}
	
	
	@RequestMapping(value="/rainwaterValveChange")
	public  ModelAndView rainwaterCalibration(){
		ModelAndView view=new ModelAndView("valveChange/rainwaterChange");
		List<Map<String,Object>> rainwaterList=rainwaterBiz.queryAll();
		for (int i=0;i<rainwaterList.size();i++){
			rainwaterList.get(i).put("viewId",i+1);
		}
		view.addObject("isValveChange", true);
		view.addObject("rainwaterList", rainwaterList);
		view.addObject("title", "企业雨水排放口阀门控制");
		return view;
		
	}
	
	@RequestMapping(value = "/radioRainwaterValveChange/{device_no}")
	public ModelAndView radioRainwaterCalibration(@PathVariable(value = "device_no") String device_no) {
		ModelAndView view = new ModelAndView("valveChange/rainwaterChange");

		view.addObject("companyList", companyBiz.getList(DictionaryEnums.RAINWATER));

		view.addObject("rainwater",rainwaterBiz.selectByDeviceNo(device_no));
		view.addObject("title", "企业雨水排放口阀门控制");
		return view;
	}
	
	
	@RequestMapping(value = "/send")
	@ResponseBody
	public CommonResult valveChangeSend(String deviceSelect,String valveSetting,String treatment,String highLevel,String lowLevel,String remoteType) {
		
		CommonResult commonResult=remoteBiz.valveChange(deviceSelect, valveSetting, treatment, highLevel, lowLevel, remoteType);
		
				return commonResult;

	}

}
